import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-07-11
 * Time: 23:25
 */
//力扣https://leetcode.cn/problems/1fGaJU/submissions/643219275/
//给定一个包含 n 个整数的数组 nums，判断 nums 中是否存在三个元素 a ，b ，c ，
// 使得 a + b + c = 0 ？请找出所有和为 0 且 不重复 的三元组。
public class Test {
    public static List<List<Integer>> threeSum(int[] nums) {
        ArrayList<ArrayList> lists=new ArrayList();
        if(nums.length<3){
            return (List)lists;
        }
        int i;  int j;  int k;
        for(i=0;i<nums.length;i++){
            for(j=i+1;j<nums.length;j++){
                for(k=j+1;k<nums.length;k++){
                    if(fun(nums[i],nums[j],lists)){
                        continue;
                    }
                    if(nums[i]+nums[j]+nums[k]==0){
                        ArrayList list=new ArrayList();
                        list.add(nums[i]);
                        list.add(nums[j]);
                        list.add(nums[k]);
                        lists.add(list);
                        break;
                    }
                }
            }
        }
        return (List)lists;
    }
    public static boolean fun( int a,int b, ArrayList<ArrayList> lists){
        if(lists.isEmpty()){
            return false;
        }
        for (int i = 0; i <lists.size() ; i++) {
            if(funs(a,b,lists.get(i))) {
                return true;
            }
        }
        return false;
    }
    public static boolean funs(int a,int b,ArrayList list){
        int n=0;
        int i=0;
        int j=0;
        for ( i=0;i<list.size();i++){
            if(a==(int)list.get(i)){
                n++;
                break;
            }
        }
        for ( j=0;j<list.size();j++){
            if(j==i){
                continue;
            }
            if(b==(int)list.get(j)){
                n++;
                break;
            }
        }
        if(n==2){
            return true;
        }
        else {
            return false;
        }
    }
    public static void main(String[] args) {
        int[] arr={1,-1,-1,0};
        int[] brr={-1,0,1,2,-1,-4};
        int[] crr={-4,-2,-2,-2,0,1,2,2,2,3,3,4,4,6,6};
        int[] drr={12,13,-10,-15,4,5,-8,11,10,3,-11,4,-10,4,-7,9,1,8,-5,-1,-9,-4,3,-14,-11,14,0,-8,-6,-2,
                14,-9,-4,11,-8,-14,-7,-9,4,10,9,9,-1,7,-10,7,1,6,-8,12,12,-10,-7,0,-9,-3,-1,-1,-4,8,12,-13,
                6,-7,13,5,-14,13,12,6,8,-2,-8,-15,-10,-3,-1,7,10,7,-4,7,4,-4,14,3,0,-10,-13,11,5,6,13,-4,6,3,
                -13,8,1,6,-9,-14,-11,-10,8,-5,-6,-7,9,-11,7,12,3,-4,-7,-6,14,8,-1,8,-4,-11};
        int[] arr1={-1,0,1,2,-1,-4,-2,-3,3,0,4};
        List list= threeSum(arr1);
        System.out.println(list.toString());
    }
}
